package com.zyy.smartcity1129.hospital;

import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.zyy.smartcity1129.BaseFragment;
import com.zyy.smartcity1129.MainActivity;
import com.zyy.smartcity1129.R;
import com.zyy.smartcity1129.data.HospitalReserInfo;
import com.zyy.smartcity1129.util.DateStringUtil;
import com.zyy.smartcity1129.util.Http;
import com.zyy.smartcity1129.util.RvAd;

import java.util.List;

/**
 * @ClassName: HospitalReserFragment$
 * @Description: 作用
 * @Author: letquit
 * @CreateDate: 2/12/2021$
 * @Version: 1.0
 */
public class HospitalReserFragment extends BaseFragment {
    private RecyclerView rvOnly;
    private Button btnNext;

    @Override
    protected int layId() {
        return R.layout.f_rv_only;
    }

    @Override
    protected String title() {
        return "挂号信息";
    }

    @Override
    protected boolean back() {
        return true;
    }

    @Override
    protected Boolean bottom() {
        return null;
    }

    @Override
    protected void init(View iv) {
        initView(iv);
        btnNext.setVisibility(View.VISIBLE);
        th(() -> {
            List<HospitalReserInfo.RowsBean> list = Http.getInstance().get("/prod-api/api/hospital/reservation/list", null, HospitalReserInfo.class, 1).getRows();
            RvAd<HospitalReserInfo.RowsBean> rvAd = new RvAd<HospitalReserInfo.RowsBean>(list, R.layout.rv_base) {
                private void initView(View vi) {
                    ig = (ImageView) vi.findViewById(R.id.ig);
                    tv1 = (TextView) vi.findViewById(R.id.tv1);
                    tv2 = (TextView) vi.findViewById(R.id.tv2);
                    tv3 = (TextView) vi.findViewById(R.id.tv3);
                    tv4 = (TextView) vi.findViewById(R.id.tv4);
                    tv5 = (TextView) vi.findViewById(R.id.tv5);
                    tv6 = (TextView) vi.findViewById(R.id.tv6);
                    lineRvPatient = (LinearLayout) vi.findViewById(R.id.lineRvPatient);
                    imgRvPatient = (ImageView) vi.findViewById(R.id.imgRvPatient);
                    tv6.setVisibility(View.GONE);
                    tv4.setVisibility(View.GONE);
                    tv5.setVisibility(View.GONE);
                    ig.setVisibility(View.GONE);
                }

                private TextView tv6;
                private TextView tv5;
                private TextView tv4;
                private TextView tv3;
                private TextView tv2;
                private TextView tv1;
                private ImageView ig;
                private ImageView imgRvPatient;
                private LinearLayout lineRvPatient;
                @Override
                protected void initR(View vi, HospitalReserInfo.RowsBean rowsBean, int p) {
                    initView(vi);
                    tv1.setText("预约科室 ：" + rowsBean.getCategoryName());
                    tv2.setText("门诊类型：" + rowsBean.getType());
//                    2020-9-21 周一 下午 14:00 2021-06-02 09:00
                    String reserveTime = rowsBean.getReserveTime();
                    String ymd = DateStringUtil.stringToYYMMDD(reserveTime);
                    String time = DateStringUtil.stringToTime(reserveTime);
                    String week = DateStringUtil.stringToWeek(reserveTime);
                    String ampm = DateStringUtil.HHToTime(reserveTime);
                    tv3.setText("预约时间：" + ymd + " " + week + " " + ampm + " " + time);
                }
            };
           ui(() ->{
               rvOnly.setLayoutManager(new LinearLayoutManager(getContext()));
               rvOnly.setAdapter(rvAd);
           });
        });
        btnNext.setOnClickListener(view -> {
            startActivity(new Intent(getContext(), MainActivity.class));
            getActivity().finish();
        });
    }

    private void initView(View iv) {
        rvOnly = (RecyclerView) iv.findViewById(R.id.rvOnly);
        btnNext = (Button) iv.findViewById(R.id.btnNext);
    }
}
